home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / lib / ubiquity / user-setup / user-setup-ask-oem < prev   
Text File  |  2009-10-28  |  7KB  |  274 lines

  1. #!/bin/bash -e
  2.  
  3. . /usr/share/debconf/confmodule
  4.  
  5. db_capb "backup"
  6.  
  7. if [ "$1" ]; then
  8.     ROOT="$1"
  9. else
  10.     ROOT=
  11. fi
  12. export ROOT
  13.  
  14. . /usr/lib/ubiquity/user-setup/functions.sh
  15.  
  16. # For the convenience of heavy testers
  17. set_special_users() {
  18.     local realname
  19.     case "$fullname" in
  20.         fjp)    realname="Frans Pop" ;;
  21.         tbm)    realname="Martin Michlmayr" ;;
  22.         *)        return 1 ;;
  23.     esac
  24.     db_set passwd/user-fullname "$realname"
  25.     userdefault=$fullname
  26.     db_fset passwd/username seen true
  27.     return 0
  28. }
  29.  
  30. # Main loop starts here. Use a state machine to allow jumping back to
  31. # previous questions.
  32. STATE=0
  33. while :; do
  34.     case "$STATE" in
  35.         0)
  36.         # Ask how the password files should be set up.
  37.         db_input low passwd/shadow || true
  38.         # Ask if root should be allowed to login.
  39.         db_input medium passwd/root-login || true
  40.         ;;
  41.         1)
  42.         db_get passwd/root-login
  43.         if [ "$RET" = false ]; then
  44.             # root password will be locked
  45.             db_set passwd/root-password ""
  46.             db_set passwd/root-password-crypted "!"
  47.         elif ! root_password; then
  48.             # First check whether the root password was preseeded
  49.             # crypted to an actual password (not locked)
  50.             db_get passwd/root-password-crypted || true
  51.             if ! test "$RET" || [ "x$RET" = "x!" ]; then
  52.                 # No preseed of the root password hash
  53.                 # we will prompt the user
  54.                 db_set passwd/root-password-crypted ""
  55.                 db_input critical passwd/root-password || true
  56.                 db_input critical passwd/root-password-again || true
  57.             fi
  58.         fi
  59.         ;;
  60.         2)
  61.         db_get passwd/root-login
  62.         if [ "$RET" = false ]; then
  63.             # root password will be locked
  64.             db_set passwd/root-password-again ""
  65.         elif ! root_password; then
  66.             # First check whether the root password was preseeded crypted
  67.             db_get passwd/root-password-crypted || true
  68.             if ! test "$RET" ; then
  69.                 # Compare the two passwords, loop back if not
  70.                 # identical, or if empty.
  71.                 db_get passwd/root-password
  72.                 ROOT_PW="$RET"
  73.                 if [ -z "$ROOT_PW" ]; then
  74.                     db_set passwd/root-login false
  75.                     STATE=1
  76.                     continue
  77.                 elif password_is_weak "$ROOT_PW"; then
  78.                     db_set user-setup/password-weak false
  79.                     db_fset user-setup/password-weak seen false
  80.                     db_input critical user-setup/password-weak
  81.                     # TODO would be better to extend state machine
  82.                     if ! db_go; then
  83.                         STATE=1
  84.                         continue
  85.                     fi
  86.                     db_get user-setup/password-weak || RET=
  87.                     if [ "$RET" != true ]; then
  88.                         # user doesn't want to force
  89.                         # weak password
  90.                         db_fset passwd/root-password seen false
  91.                         db_fset passwd/root-password-again seen false
  92.                         STATE=1
  93.                         continue
  94.                     fi
  95.                 fi
  96.                 db_get passwd/root-password-again
  97.                 if [ "$ROOT_PW" != "$RET" ]; then
  98.                     db_fset user-setup/password-mismatch seen false
  99.                     db_input critical user-setup/password-mismatch
  100.                     db_fset passwd/root-password seen false
  101.                     db_fset passwd/root-password-again seen false
  102.                     STATE=1
  103.                     continue
  104.                 fi
  105.                 ROOT_PW=''
  106.             fi
  107.         fi
  108.         ;;
  109.         3)
  110.         # Ask if a non-root user should be made, if there is not
  111.         # already one.
  112.         db_get passwd/root-login
  113.         if [ "$RET" = false ]; then
  114.             # always make non-root user; this user will be able
  115.             # to sudo to root
  116.             db_set passwd/make-user true
  117.         elif ! is_system_user; then
  118.             db_input medium passwd/make-user || true
  119.         fi
  120.         ;;
  121.         4)
  122.         # Prompt for user info.
  123.         db_get passwd/make-user
  124.         if [ "$RET" = true ] && ! is_system_user; then
  125.             db_input critical passwd/user-fullname || true
  126.         fi
  127.         ;;
  128.         5)
  129.         # Prompt for user info.
  130.         db_get passwd/make-user
  131.         if [ "$RET" = true ] && ! is_system_user; then
  132.             LOOP=""
  133.             db_get passwd/username
  134.             if [ -z "$RET" ]; then
  135.                 db_get passwd/user-fullname
  136.                 fullname=$RET
  137.                 if ! set_special_users; then
  138.                     userdefault=$(echo "$fullname" | \
  139.                         sed 's/ .*//' | LC_ALL=C tr A-Z a-z)
  140.                 fi
  141.                 if test -n "$userdefault" && \
  142.                     LC_ALL=C expr "$userdefault" : '[a-z][-a-z0-9]*$' >/dev/null; then
  143.                     db_set passwd/username "$userdefault"
  144.                 fi
  145.             fi
  146.             db_input critical passwd/username || true
  147.         fi
  148.         ;;
  149.         6)
  150.         # Verify user.
  151.         db_get passwd/make-user
  152.         if [ "$RET" = true ] && ! is_system_user; then
  153.             # Verify the user name, loop with message if bad.
  154.             db_get passwd/username
  155.             USER="$RET"
  156.             if ! LC_ALL=C expr "$USER" : '[a-z][-a-z0-9_]*$' >/dev/null; then
  157.                 db_fset passwd/username seen false
  158.                 db_fset passwd/username-bad seen false
  159.                 db_input critical passwd/username-bad
  160.                 STATE=3
  161.                 continue
  162.             fi
  163.             
  164.             if grep -v '^#' /usr/lib/ubiquity/user-setup/reserved-usernames-oem | \
  165.                grep -q "^$USER\$"; then
  166.                 db_fset passwd/username seen false
  167.                 db_fset passwd/username-reserved seen false
  168.                 db_subst passwd/username-reserved USERNAME "$USER"
  169.                 db_input critical passwd/username-reserved
  170.                 STATE=3
  171.                 continue
  172.             fi
  173.  
  174.             db_get passwd/user-password-crypted || true
  175.             if ! test "$RET" ; then
  176.                 db_input critical passwd/user-password || true
  177.                 db_input critical passwd/user-password-again || true
  178.             fi
  179.         fi
  180.         ;;
  181.         7)
  182.         db_get passwd/make-user
  183.         if [ "$RET" = true ] && ! is_system_user; then
  184.             db_get passwd/user-password-crypted || true
  185.             if ! test "$RET" ; then
  186.                 # Compare the two passwords, loop with message if not
  187.                 # identical
  188.                 db_get passwd/user-password
  189.                 USER_PW="$RET"
  190.                 db_get passwd/user-password-again
  191.                 if [ "$USER_PW" != "$RET" ]; then
  192.                     db_set passwd/user-password ""
  193.                     db_set passwd/user-password-again ""
  194.                     db_fset user-setup/password-mismatch seen false
  195.                     db_input critical user-setup/password-mismatch
  196.                     db_fset passwd/user-password seen false
  197.                     db_fset passwd/user-password-again seen false
  198.                     STATE=6
  199.                     continue
  200.                 fi
  201.                 # Loop if the password is empty, and it's not
  202.                 # specifically allowed by preseeding
  203.                 if password_is_empty "$USER_PW"; then
  204.                     db_set passwd/user-password ""
  205.                     db_set passwd/user-password-again ""
  206.                     db_fset user-setup/password-empty seen false
  207.                     db_input critical user-setup/password-empty
  208.                     db_fset passwd/user-password seen false
  209.                     db_fset passwd/user-password-again seen false
  210.                     STATE=6
  211.                     continue
  212.                 elif [ "$USER_PW" ] && password_is_weak "$USER_PW"; then
  213.                     db_set user-setup/password-weak false
  214.                     db_fset user-setup/password-weak seen false
  215.                     db_input critical user-setup/password-weak
  216.                     # TODO would be better to extend state machine
  217.                     if ! db_go; then
  218.                         STATE=6
  219.                         continue
  220.                     fi
  221.                     db_get user-setup/password-weak || RET=
  222.                     if [ "$RET" != true ]; then
  223.                         # user doesn't want to force
  224.                         # weak password
  225.                         db_set passwd/user-password ""
  226.                         db_set passwd/user-password-again ""
  227.                         db_fset passwd/user-password seen false
  228.                         db_fset passwd/user-password-again seen false
  229.                         STATE=6
  230.                         continue
  231.                     fi
  232.                 fi
  233.             fi
  234.         fi
  235.         ;;
  236.         8)
  237.         db_get passwd/username
  238.         USER="$RET"
  239.         db_get passwd/make-user
  240.         if [ "$RET" = true ] && [ ! -d "$ROOT/home/$USER" ]; then
  241.             db_input medium user-setup/encrypt-home || true
  242.         fi
  243.         ;;
  244.         9)
  245.         ecryptfs_in_use=
  246.         for homedir in "$ROOT/home"/*; do
  247.             if [ -d "$homedir/.ecryptfs" ]; then
  248.                 ecryptfs_in_use=1
  249.                 break
  250.             fi
  251.         done
  252.         if [ "$ecryptfs_in_use" ] || \
  253.            (db_get user-setup/encrypt-home && [ "$RET" = true ]); then
  254.             apt-install ecryptfs-utils 2>/dev/null
  255.             apt-install cryptsetup 2>/dev/null
  256.         fi
  257.         ;;
  258.         *)
  259.         break
  260.         ;;
  261.     esac
  262.  
  263.     if db_go; then
  264.         STATE=$(($STATE + 1))
  265.     else
  266.         STATE=$(($STATE - 1))
  267.     fi
  268.     #echo "ON STATE: $STATE"
  269. done
  270.  
  271. if [ "$STATE" = -1 ]; then
  272.     exit 10
  273. fi
  274.